home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / KMAGV3.ZIP / KMAGUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-01-11  |  11KB  |  386 lines

  1. {THE KING MAGAZINE UNIT FOR PASCAL          }
  2. {WRITING BY THE KING IN 01/02/96            }
  3. Unit KMagUnit;
  4. Interface
  5. Uses Dos;
  6.  
  7.  
  8. Type
  9. {A Picture Type}
  10.     PicType = Array[0..64000] Of Byte;     {Pointer To The Pictures}
  11.     PicTypeP = ^PicType;
  12. {Red , Green , Blue Type}
  13.     RGB = Record                           {A Record Of Red,Green,Blue}
  14.         R,G,B:Byte;
  15.     End;
  16. {Palette Type}
  17.     PalType = Array[0..255] Of RGB;        {256 Color Of Red Green Blue}
  18.  
  19. {Mouse Button Types}
  20.     ButtonType = (None,Left,Right,LeftRight);
  21.  
  22. {Mouse Type}
  23.     MouseType = Record
  24.         X,Y:Word;
  25.         Buttons : ButtonType;
  26.     End;
  27.  
  28. {Cel Format Header}
  29.     CelHeader=Record                {A Cel File Header}
  30.         Sign:Word;
  31.         W,H:Word;
  32.         X,Y:Word;
  33.         Depth:Byte;
  34.         Compress:Byte;
  35.         Data:LongInt;
  36.         Filler:Array[1..16] OF Byte;
  37.         Pal:PalType;
  38.      End;
  39.  
  40. Var
  41.     Keys : Array[1..128] Of Boolean;  {The Keys status}
  42.     Mouse:MouseType;
  43.  
  44.  
  45. {-------------------Set Modes Routines-----------------}
  46.  
  47. Procedure SetMode;
  48. Procedure SetTextMode;
  49.  
  50. {-------------------Graphics Routines------------------}
  51.  
  52. Procedure PutPixel(X,Y:Integer;Col:Byte);
  53. Procedure ShowPic(Pic:PicTypeP);
  54.  
  55. {--------------------Palette Routines-------------------}
  56.  
  57. Procedure GetColor(Col:Byte;Var R,G,B:Byte);
  58. Procedure SetColor(Col:Byte;R,G,B:Byte);
  59. Procedure ShowPal(Var Pal:PalType);
  60. Procedure GetPal(Var Pal:PalType);
  61. Procedure FadeTo(Pal,ToPal:PalType);
  62.  
  63. {----------------------File Formats---------------------}
  64.  
  65. Function LoadCel(Name:String;Var Where;Var Pal:PalType):Boolean;
  66.  
  67. {------------------------Effects------------------------}
  68.  
  69. Procedure MakeCrossFade(Pic1,Pic2:PicTypeP;Var Pic3:PicTypeP;
  70.                         Var PalP1,PalP2,PalCp1,PalCp2:PalType);
  71.  
  72. {-------------------KeyBoard Routines-------------------}
  73.  
  74. Procedure InitKeyBoard;
  75. Procedure RestoreKeyBoard;
  76.  
  77. {------------------------------Mouse Routines------------------------------}
  78.  
  79. Function ResetMouse:Boolean;
  80. Procedure GetMouse(Var Mouse:MouseType);
  81. Procedure ShowMouse;
  82. Procedure HideMouse;
  83.  
  84. Implementation
  85.  
  86. Var
  87.     OldInt9 : Procedure;
  88. {-----------------------------Set Modes Routines---------------------------}
  89.  
  90. {------------------------------------------------}
  91. {Set Mode To Mode 13H , 320x200x256 Colors..     }
  92. {------------------------------------------------}
  93.  
  94. Procedure SetMode;Assembler;
  95. Asm
  96.        Mov Ah,00h  {Function 00,13 Interrupt 10h / SET MODE}
  97.     Mov Al,13h
  98.     Int 10h     {SETING TO MODE 13H}
  99. End;
  100.  
  101. {------------------------------------------------}
  102. {Set Mode To Mode 3H , 80x25x16 Colors..         }
  103. {------------------------------------------------}
  104. Procedure SetTextMode;Assembler;
  105. Asm
  106.     Mov Ah,00h {Function 00,3 Interrupt 10h / SET MODE}
  107.     Mov Al,3h
  108.     Int 10h    {SET MODE TO MODE 3 / TEXT MODE}
  109. End;
  110.  
  111. {----------------------------Graphics Routines-----------------------------}
  112.  
  113. {------------------------------------------------}
  114. {Plot a single pixel on the screen .             }
  115. {------------------------------------------------}
  116. Procedure PutPixel(X,Y:Integer;Col:Byte);Assembler;
  117. Asm
  118.     Mov Ax,0a000h     {Ax = SEGMENT OF THE SCREEN}
  119.     Mov Es,Ax         {Es = SEGMENT OF THE SCREEN}
  120.     Mov Ax,320        {Ax = MAX VERTICAL LINE}
  121.     Mul Y             {Ax = AX * Y = HORIZONTAL LINE}
  122.     Add Ax,X          {Ax = VERTICAL LINE + HORIZONTAL LINE = OFFSET}
  123.     Mov Di,Ax         {DI = OFFSET}
  124.     Mov Al,Col        {AL = COLOR}
  125.     StoSb             {[0A000h:OFFSET] = COLOR}
  126. End;
  127.  
  128. {-----------------------------------------}
  129. { Show Picture On Screen .                }
  130. {-----------------------------------------}
  131.  
  132. Procedure ShowPic(Pic:PicTypeP);Assembler;
  133.   Asm
  134.     Push Ds
  135.     Mov Ax,Word(Pic+2)                {Take The Segment Of Pic}
  136.     Mov Ds,Ax
  137.     Xor Si,Si                         {Si = 0}
  138.     Mov Ax,0a000h
  139.     Mov Es,Ax
  140.     Xor Di,Di                         {Di = 0}
  141.     Mov Cx,32000                      {32000*2 = 64000}
  142.     Rep MovSw                         {Move 32000*2 Bytes}
  143.     Pop Ds
  144.  End;
  145.  
  146. {------------------------------Palette Routines----------------------------}
  147.  
  148. {-------------------------------------------------------}
  149. {Get Red Green And Blue From a Color                    }
  150. {-------------------------------------------------------}
  151.  
  152. Procedure GetColor(Col:Byte;Var R,G,B:Byte);Assembler;
  153. ASM
  154.     Mov Dx,3c7H                  {Set To GET COLOR}
  155.     Mov Al,Col
  156.     Out Dx,Al
  157.     Inc Dx                       {Dx = 3c8H}
  158.     Inc Dx                       {Dx = 3c9H}
  159.     Les Di,R                     {Es:Di = R}
  160.     In Al,Dx                     {Get Red Value}
  161.     Mov [Es:Di],Al               {R = Red Value}
  162.     In Al,Dx                     {Get Green Value}
  163.     Les Di,G                     {Es:Di = G}
  164.     Mov [Es:Di],Al               {G = Green Value}
  165.     In Al,Dx                     {Get Blue Value}
  166.     Les Di,B                     {Es:Di = B}
  167.     Mov [Es:Di],Al               {B = Blue Value}
  168. END;
  169.  
  170. {-------------------------------------------------------}
  171. {Set Red Green And Blue To a Color                      }
  172. {-------------------------------------------------------}
  173.  
  174. Procedure SetColor(Col:Byte;R,G,B:Byte);Assembler;
  175. Asm
  176.     Mov Dx,3c8h                  {SET TO SET COLOR}
  177.     Mov Al,Col
  178.     Out Dx,Al
  179.     Inc Dx                       {DX = 3c9h}
  180.     Mov Al,R                     {Senting Red Value}
  181.     Out Dx,Al
  182.     Mov Al,G                     {Senting Green Value}
  183.     Out Dx,Al
  184.     Mov Al,B                     {Senting Blue Value}
  185.     Out Dx,Al
  186. End;
  187. {---------------------------------------------------}
  188. { Show The Palette                                  }
  189. {---------------------------------------------------}
  190. Procedure ShowPal(Var Pal:PalType);
  191. Var T:Byte;
  192. Begin
  193.     For T:=0 To 255 Do
  194.         SetColor(T,Pal[T].R,Pal[T].G,Pal[T].B);
  195. End;
  196. {---------------------------------------------------}
  197. { Get The Use Palette From The Screen               }
  198. {---------------------------------------------------}
  199.  
  200. Procedure GetPal(Var Pal:PalType);
  201. Var T:Byte;
  202. Begin
  203.     For T:=0 To 255 Do
  204.         GetColor(T,Pal[T].R,Pal[T].G,Pal[T].B);
  205. End;
  206.  
  207. {---------------------------------------------------}
  208. { Fade To The Screen From Palette To Palette.       }
  209. {---------------------------------------------------}
  210. Procedure FadeTo(Pal,ToPal:PalType);
  211. Var
  212.     T,T1:Byte;
  213. Begin
  214.     For T1:=1 To 63 Do
  215.     Begin
  216.         For T:=1 To 255 Do
  217.         Begin
  218.             If Pal[T].R > ToPal[T].R Then
  219.                 Dec(Pal[T].R);
  220.             If Pal[T].R < ToPal[T].R Then
  221.                 Inc(Pal[T].R);
  222.             If Pal[T].G > ToPal[T].G Then
  223.                 Dec(Pal[T].G);
  224.             If Pal[T].G < ToPal[T].G Then
  225.                 Inc(Pal[T].G);
  226.             If Pal[T].B > ToPal[T].B Then
  227.                 Dec(Pal[T].B);
  228.             If Pal[T].B < ToPal[T].B Then
  229.                 Inc(Pal[T].B);
  230.         End;
  231.         ShowPal(Pal);
  232.     End;
  233. End;
  234. {-------------------------------File Formats-------------------------------}
  235.  
  236. Function LoadCel(Name:String;Var Where;Var Pal:PalType):Boolean;
  237. Var F:File;
  238.     Cel:CelHeader;
  239. Begin
  240.     {$I-}
  241.     Assign(F,Name);
  242.     Reset(F,1);
  243.     {$I+}
  244.     If IoResult=0 Then
  245.         Begin
  246.             LoadCel:=True;
  247.             BlockRead(F,Cel,SizeOf(Cel));
  248.             BlockRead(F,Where,FileSize(F)-SizeOf(Cel));
  249.             Pal:=Cel.Pal;
  250.             Close(F);
  251.         End
  252.         Else
  253.         Begin
  254.             LoadCel:=False;
  255.         End;
  256. End;
  257.  
  258. {---------------------------------Effects----------------------------------}
  259.  
  260. {---------------------------------------------}
  261. {Build The Picture Of The Cross Fade          }
  262. {---------------------------------------------}
  263.  
  264. Procedure MakeCrossFade(Pic1,Pic2:PicTypeP;Var Pic3:PicTypeP;
  265.                         Var PalP1,PalP2,PalCp1,PalCp2:PalType);
  266. Var
  267.     Colors : Array[0..255] Of Record
  268.         Pix1,Pix2:Byte;
  269. End;
  270.     T:Word;
  271.     T1:Word;
  272.     Num:Word;
  273.     Pix1,Pix2:Byte;
  274. Begin
  275.     T:=0;
  276.     Num := 1;
  277.     Repeat
  278.         Pix1 := PIC1^[T];
  279.         Pix2 := PIC2^[T];
  280.         For T1 := 0 To Num - 1 Do
  281.         Begin
  282.             If (Num <> 1) And (Pix1=Colors[T1].Pix1) And (Pix2=Colors[T1].Pix2) Then
  283.             Begin
  284.                 PIC1^[T] := T1;
  285.                 T1:=256;
  286.                 Break;
  287.             End
  288.         End;
  289.  
  290.         If T1 <> 256 Then
  291.         Begin
  292.               PIC1^[T] := Num;
  293.             PalCP1[Num] := PalP1[Pix1];
  294.             PalCP2[Num] := PalP2[Pix2];
  295.             Colors[Num].Pix1 := Pix1;
  296.             Colors[Num].Pix2 := Pix2;
  297.             Num := Num + 1;
  298.         End;
  299.         Inc(T);
  300.         If Num > 255 Then
  301.         Begin
  302.             Writeln('More Then 256 Colors . ');
  303.             Halt;
  304.         End;
  305.     Until(T=64000);
  306. End;
  307.  
  308. {-----------------------------Keyboard Routines------------------------------}
  309.  
  310. {--------------------------------------------}
  311. {New Interrupt 9 for handle with the keyboard}
  312. {--------------------------------------------}
  313.  
  314.  
  315. Procedure NewInt9;interrupt;
  316. Begin
  317.     Keys[Port[$60] Mod 128] := (Port[$60] < 128) ;
  318.     {Checking if Port[$60] < 128 , If He Is , Keys[Port[$60] Mod 128]
  319.     Is True Else False}
  320.     Asm
  321.         PushF                       {Pushing Flags}
  322.     End;
  323.     OldInt9;                        {Calling the old interrupt}
  324.     Mem[$0040:$001A] := Mem[$0040:$001C];
  325.     {Puting The Tail And The Head , for clear the buffer}
  326. End;
  327.  
  328. {-------------------------------------------}
  329. {         Init The new interrupt            }
  330. {-------------------------------------------}
  331.  
  332. Procedure InitKeyboard;
  333. Begin
  334.     GetIntVec($9,@OldInt9);
  335.     SetIntVec($9,@NewInt9);
  336. End;
  337.  
  338. {--------------------------------------}
  339. {      Restore The Old interrupt       }
  340. {--------------------------------------}
  341. Procedure RestoreKeyBoard;
  342. Begin
  343.     SetIntVec($9,@OldInt9);
  344. End;
  345.  
  346. {------------------------------Mouse Routines------------------------------}
  347.  
  348. {--------------------------------------}
  349. {         Get the mouse status         }
  350. {--------------------------------------}
  351.  
  352. Procedure GetMouse(Var Mouse:MouseType);Assembler;
  353.     Asm
  354.         Push Ds                 {Saving DS}
  355.         Mov Ax,0003h            {Function 0003H INT 33H GET STATUS}
  356.         Int 33h
  357.         Lds Si,Mouse            {[DS:SI] = MOUSE}
  358.         Shr CX,3                {FOR DIVIDE IT WITH 8}
  359.         Shr DX,3
  360.         Mov [Ds:Si],CX          {[DS:SI] = X = CX}
  361.         Mov [Ds:Si+2],DX        {[DS:SI+2] = Y = DX}
  362.         Mov [DS:Si+4],BX        {[DS:SI+4] = BUTTON = BX}
  363.         Pop Ds                  {Restoring DS}
  364.     End;
  365.  
  366. {Thus function Reseting the mouse and return true if the mouse is installed}
  367. Function ResetMouse:Boolean;Assembler;
  368. Asm
  369.     Mov Ax,0000h
  370.     Int 33h
  371. End;
  372.  
  373. {Show the mouse on the screen}
  374. Procedure ShowMouse;Assembler;
  375. Asm
  376.     Mov Ax,0001h
  377.     Int 33h
  378. End;
  379. {Hide the mouse from the screen}
  380. Procedure HideMouse;Assembler;
  381. Asm
  382.     Mov Ax,0002h
  383.     Int 33h
  384. End;
  385.  
  386. End.